/**
 * 
 */
package com.yunyike.controller.merchandiseBrand;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunyike.constants.CommonConstant;
import com.yunyike.constants.RequestConstant;
import com.yunyike.constants.ResponseConstant;
import com.yunyike.controller.BaseController;
import com.yunyike.model.MerchandiseBrand;
import com.yunyike.response.Response;
import com.yunyike.service.IMerchandiseBrandService;

/**
 * @author zhengqiang.shi
 * 2016-4-8 下午4:56:14
 */
@Controller
@RequestMapping(value=RequestConstant.MERCHANDISE_BRAND)
public class MerchandiseBrandController extends BaseController{

	private static Logger log = LoggerFactory.getLogger(MerchandiseBrandController.class);
	
	@Autowired
	private IMerchandiseBrandService merchandiseBrandService;
	
	/**
	 * 查询商品品牌 返回json数据
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value=RequestConstant.MERCHANDISE_BRAND_LIST)
	public void getAllMerchandiseBrandsPost(HttpServletResponse response){
		
		// response object
		Response res = new Response();
		
		List<MerchandiseBrand> list;
		try {
			list = merchandiseBrandService.findAllMerchandiseBrand();
		} catch (Exception e) {
			log.error("merchandiseBrandService.findAllMerchandiseBrand() has error.message:"+e.getMessage(),e);
			res.getResult().setCode(CommonConstant.NUMBER__3);
			res.getResult().setMessage(ResponseConstant.message.get(CommonConstant.NUMBER__3));
			returnDatas(res, response);
			return;
		}
		
		if(list == null || list.isEmpty()){
			log.info("no MerchandiseBrand find.");
			res.getResult().setCode(CommonConstant.NUMBER__2);
			res.getResult().setMessage(ResponseConstant.message.get(CommonConstant.NUMBER__2));
			returnDatas(res, response);
			return;
		}
		
		res.setData(list);
		returnDatas(res, response);
		return;
	}
}
